<?php
namespace app\services;
// use think\facade\Env;

class NodeService
{
    public function __construct(){
        //echo 'action';
        // define('APP_PATH', Env::get('app_path'));  // 定义应用目录
    }

    //获取应用下的模块名称
    public function getModule(){
        $dir = array();
        $path = APP_PATH . '/*/';
        $dir_name = glob($path);  // glob() 函数返回匹配指定模式的文件名或目录
        foreach ($dir_name as $value){
            array_push($dir, basename($value));  // basename() 函数返回路径中的文件名部分。
        }
        return $dir;
    }

    //获取所有控制器名称
    public function getController($module){
        if(empty($module)) return false;
        $module_path = APP_PATH . '/' . $module . '/controller/';  //控制器路径
        if(!is_dir($module_path)) return false;
        $module_path .= '/*.php';

        $ary_files = glob($module_path);
        $files     = array();
        //定义需排除的控制器
        $inherents_functions = array('FatherConer','Index','Login','Father');
        foreach ($ary_files as $file) {

            if(in_array(basename($file, '.php'), $inherents_functions)){
                continue;
            }
            if (is_dir($file)) {
                continue;
            }else {
                $files[] = basename($file, '.php');
            }
        }
        return $files;
    }

    //获取所有方法名称
    public function getAction($controller){
        if(empty($controller)) return false;

        $con = controller($controller);  // 实例化 controller

        $functions = get_class_methods($con);  //get_class_methods()返回由类的方法名组成的数组
        $customer_functions = [];
        //定义需排除的方法
        $inherents_functions = array('_initialize','__construct','getActionName','isAjax','display','show','fetch','buildHtml','assign','theme','__set','get','__get','__isset','__call','error','success','ajaxReturn','redirect','__destruct', '_empty','__debugInfo','registerMiddleware','getRequests','dataProcess','getErrorMsg','selectChannel','getUserType','getDataTable','orderInfo','checkIp','resetKey','getChannelNote');

        foreach ($functions as $func){
            if(!in_array($func, $inherents_functions)){
                $customer_functions[] = $func;
            }
        }
        return $customer_functions;
    }
}